import {areaSelect} from "@/api/system/common";
import {allUmsMember} from "@/api/ums/member";

const state = {
  productCategories: [],
  brandList: [],
  areaSelect: [],
  memberList: []
}
const mutations = {
  SET_PRODUCT_CATEGORIES: (state, value) => {
      state.productCategories = value
    },
  SET_areaSelect: (state, value) => {
    state.areaSelect = value
  },
  SET_BRAND_LIST: (state, value) => {
    state.brandList = value
  },
  SET_MEMBER_LIST: (state, value) => {
    state.memberList = value
  }
}
const actions = {
  loadAreaSelect({ commit, state }, force = false) {
    if (!force && state.areaSelect.length > 0) {
      return Promise.resolve();
    }
    return areaSelect({},{}).then(res => {
      commit('SET_areaSelect', res.data);
    })
  },
  loadMemberList({ commit, state }, force = false) {
    if (!force && state.memberList.length > 0) {
      return Promise.resolve();
    }
    return allUmsMember({}).then(res => {
      commit('SET_MEMBER_LIST', res);
    })
  },
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
